Repository navigation
feat(starter): surface CNG permission 403s in the demo - #26
Merged
Merged
Conversation
`withAppAuthentication` now awaits the route handler inside a try/catch and
translates a `CngPermissionError` into a 403 JSON response carrying the
gateway's message and the missing `permissions`. Doing it in the wrapper keeps
every route from repeating the same catch, and stops an expected
misconfigured-install failure from surfacing as an unhandled 500 with a stack
trace. Any other rejection is re-thrown unchanged.
The CNG example view already rendered `err.message`, so the gateway's text
("...missing the required permission: products:read") now reaches the UI
verbatim instead of being flattened to a generic failure.
`CngPermissionError` is only exported from @peektravel/app-utilities 0.8.2, so
the starter template's dependency moves from ^0.8.0 to ^0.8.2.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
refactor(starter): rescue CNG permission 403s in the route, not the wrapper
`withAppAuthentication` is the shared entry point for every platform the app is
embedded into (Peek, Connect&GO, ACME), so teaching it about `CngPermissionError`
put one platform's failure mode in a file that serves all of them. Revert the
wrapper to its platform-agnostic form and move the rescue into the CNG example
route that actually makes the call.
The 403 response shape is unchanged — the gateway's message plus the missing
`permissions` — and so is the demo view that renders it. The two wrapper tests
move alongside the code, into the activities route's suite.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
remove from top level; added by mistake
dumb comment
coladarci
force-pushed
the
starter/cng-permission-error-403
branch
from
September 15, 2026 19:10
4c9f067 to
a14c2c4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the error-handling changes from the local
cng-test-starter-kitworking tree into the scaffolding template, so every newly scaffolded app gets them.What changed
app/examples/cng/main/api/activities/route.ts— the route wraps itscng.getAllActivities()call and translates aCngPermissionErrorinto a 403 JSON response:This is an expected failure for an install whose manifest grants fewer permissions than the route calls for — not a bug — so it becomes a response the client can render instead of an unhandled throw that Next.js reports as a 500 with a stack trace. The
permissionsarray lets the client name exactly what to grant. Any other rejection is re-thrown unchanged.The rescue deliberately lives in the CNG route rather than in
withAppAuthentication: that wrapper is the shared entry point for every platform the app is embedded into (Peek, Connect&GO, ACME), and only CNG throws this error.lib/with-app.tsis untouched by this PR.app/examples/cng/main/view/page.tsx— the demo already renderederr.message; a comment now records why it must stay verbatim. The gateway's text ("CNG request forbidden: the app is missing the required permission: products:read") reaches the UI instead of being flattened to a generic failure.Tests — three added: the 403 response shape with named permissions and the re-throw of any other failure (both in the activities route suite), plus the demo surfacing the gateway message verbatim.
Dependency bump
CngPermissionErroris only exported from@peektravel/app-utilities0.8.2 — the published 0.8.0 and 0.8.1 tarballs don't have it. The template's dependency therefore moves^0.8.0→^0.8.2with its lockfile regenerated, otherwise a freshly scaffolded app fails to typecheck on the import.The root
package.json/pnpm-lock.yamlalso gain@peektravel/app-utilities@^0.8.2as a CLI dependency. That change was already in the working tree and is carried along here; nothing undersrc/imports it yet.Verification
tsc -bandvitest runin this repo — clean, 23 passed, including thepeek inite2e that scaffolds and installs deps against the bumped templatecng-test-starter-kit(which has the deps installed) and its full suite run there:tsc --noEmitclean, 181 tests passedNo CLI command, flag, or extension behavior changed, so the
cliskill needs no sync. Worth a follow-up:src/skills/platform/cng/backoffice-api/SKILL.mddocumentsCngApiErrorand could teach this 403 pattern to app-building agents.🤖 Generated with Claude Code